<template>
  <div class="kgo-search-project">
     <form class="layui-form" action="" lay-filter="kgo-search-project-form-filter">
            <div class="layui-form-item layui-form-pane kgo-form-alone-item">
                    <label class="layui-form-label">当前项目</label>
                    <div class="layui-input-inline">
                    <select  class="kgo-search-project-select-act" lay-verify="required" lay-search="" lay-filter="kgo-search-project-filter">
                        <option v-for="option in options" :value="option.sysCode">{{option.sysValue}}</option>
                    </select>
                    </div>
            </div>
    </form>
  </div>
</template>

<script>
//系统信息

export default {
  props:{
      catalogueCode:{
          default:null
      },
      url:{
        default:null
      },
      disable:{
        default:false
      }
    },
     data () {
        return {
           searchData:"",
           options:[],
        }
    },
    created(){
        this.getSysCode();
    },
   mounted(){
      var that = this;
      layui.form.on('select(kgo-search-project-filter)', function(data){
          that.searchData = data.value;
          //将项目ID更新到vuex里进行全局使用
          that.$store.commit('updateProjectId', that.searchData);
          that.$router.push({
                path:"/projectHome",
                name:'主页'
            });

      });

      $('.kgo-search-project-select-act').val(that.searchData);
      layui.form.render('select');
   },
   methods:{
     /**=============================================
      *
      */
      getSysCode:function(){
          var $ = layui.$;
          var _catalogueCode = this.catalogueCode;
          var s_url = ""
          if(this.url==null){
            s_url = this.$store.state.RootURL + "/sys/code";
          }else{
             s_url = this.$store.state.RootURL + this.url;
          }

          var that = this;
          $.ajax({
              url: s_url,
              type:"get",
              async: false,
              dataType:'json',
              data: {"catalogueCode":_catalogueCode},
              success: function(data){
                //console.log("项目 code " + JSON.stringify(data.data));
                that.options=data.data;
                that.searchData = that.options[0].sysCode;
                  //将项目ID更新到vuex里进行全局使用
                that.$store.commit('updateProjectId', that.searchData);
              }
          });
      }
    }
}
</script>

<style lang="scss">
.kgo-search-project{
  min-width: 300px;
  max-width: 400px;
  position: absolute;
  left: 240px;
  top:10px;
}
</style>
